package com.ruoyi.web.controller.his;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.his.domain.vo.HFtotleVo;
import com.ruoyi.system.domain.HisLicensedOverWarning;
import com.ruoyi.system.domain.HisVerifyOverdueWarning;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.his.domain.HisPunish;
import com.ruoyi.his.service.IHisPunishService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.validation.Valid;

/**
 * 【请填写功能名称】Controller
 * 
 * @author Alan
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/his/punish")
public class HisPunishController extends BaseController
{
    @Autowired
    private IHisPunishService hisPunishService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('his:punish:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisPunish hisPunish)
    {
        startPage();
        List<HisPunish> list = hisPunishService.selectHisPunishList(hisPunish);
        return getDataTable(list);
    }
    @GetMapping("/myVerifyWarning")
    public TableDataInfo myVerifyWarning(HisVerifyOverdueWarning hisVerifyOverdueWarning)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        hisVerifyOverdueWarning.setSignature(loginUser.getSignature());
        hisVerifyOverdueWarning.setHospitalId(loginUser.getHospitalId());
        List<HisVerifyOverdueWarning> list = hisPunishService.myVerifyWarningInfo(hisVerifyOverdueWarning);
        return getDataTable(list);
    }
    @GetMapping("/myLicencedWarning")
    public TableDataInfo mylicencedWarning(HisLicensedOverWarning hisLicensedOverWarning)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        hisLicensedOverWarning.setHospitalId(loginUser.getHospitalId());
        hisLicensedOverWarning.setSignature(loginUser.getSignature());
        List<HisLicensedOverWarning> hisLicensedOverWarnings
                = hisPunishService.myHisLicensedOverWarningList(hisLicensedOverWarning);

        return getDataTable(hisLicensedOverWarnings);
    }
    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('his:punish:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HisPunish hisPunish)
    {
        List<HisPunish> list = hisPunishService.selectHisPunishList(hisPunish);
        ExcelUtil<HisPunish> util = new ExcelUtil<HisPunish>(HisPunish.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('his:punish:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hisPunishService.selectHisPunishById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('his:punish:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated HisPunish hisPunish)
    {
        return toAjax(hisPunishService.insertHisPunish(hisPunish));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('his:punish:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisPunish hisPunish)
    {
        hisPunish.setReTime(new Date());
//        return toAjax(hisPunishService.updateHisPunish(hisPunish));
        return toAjax(hisPunishService.InertOrUpdata(hisPunish));
    }
    @GetMapping("/getTotleList")
    public AjaxResult getTotleList(){
        LoginUser loginUser = getLoginUser();
        HisPunish hisPunish = new HisPunish();
        hisPunish.setHospitalId(loginUser.getHospitalId());
        hisPunish.setSignature(loginUser.getSignature());
        List<HFtotleVo> list =  hisPunishService.getTotleList(hisPunish);
        return AjaxResult.success(list);
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('his:punish:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hisPunishService.deleteHisPunishByIds(ids));
    }
}
